// 预加载文件桥
const { contextBridge, ipcRenderer,clipboard,desktopCapturer} = require('electron')
// console.log(contextBridge,'预加载文件')
// const clipboard = require('electron').;
console.log(ipcRenderer)
console.log(clipboard,'clipboard')
const  handleSend = async () => {
   let fallback =await ipcRenderer.invoke('send-event','hahahahah')
    console.log(fallback)
    console.log(clipboard.writeText,'paste')
}
const copy = ()=>{
    // console.log(clipboard.,'paste')
    clipboard.writeText('cocococo')
}
const paste = ()=>{
   const text  = clipboard.readText()
    console.log(text,'paste')
}
// 截图

const captureDesktop =async ()=>{
 const  res =await ipcRenderer.invoke('capturer')
    console.log(res,'capturer')
    for (const rea of res) {

        if (rea.name ==='Steam'){
            console.log(rea,'imgUrl1')
            let str = rea.thumbnail.crop({x:0,y:30,width:1200,height:1200})
            let imgUrl = str.toDataURL()
            return imgUrl
        }

    }
}
contextBridge.exposeInMainWorld('myApi', {
  // 获取主进程数据
    platform:process.platform,
    handleSend,
    copy,
    paste,
    captureDesktop
  })
